<template>
    <div>
      <a-table
        ref="table"
        size="middle"
        rowKey="id"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="materialDesc" slot-scope="text, record">
          <j-ellipsis :value="text" :length="18"/>
        </template>
        <template slot="status_dictText" slot-scope="text, record">
          <a-tag :color="getStatusColor(record.status)">
            {{text}}
          </a-tag>
        </template>
        <template slot="remark" slot-scope="text, record">
          <j-ellipsis :value="text" :length="12"/>
        </template>
      </a-table>
    </div>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { mixinDevice } from '@/utils/mixin'
  import '@/assets/less/TableExpand.less'
  import { filterObj } from '@/utils/util';
  import {getAction} from "@/api/manage";

  export default {
    name: "MmPurchaseRequisitionDetailTable",
    mixins:[JeecgListMixin,mixinDevice],
    components: {
    },
    props:{
      initQueryParam:{},
      initAddModel:{}
    },
    data () {
      return {
        description: '采购申请明细列表',
        // 表头
        columns: [
          {
            title: '行号',
            align:"center",
            dataIndex: 'lineNo',
            width: 70
          },
          {
            title:'物料描述',
            align:"center",
            dataIndex: 'materialDesc',
            scopedSlots: { customRender: 'materialDesc' },
            width: 240
          },
          {
            title: '单位',
            align:"center",
            dataIndex: 'unit_dictText',
            width: 70
          },
          {
            title: '申请数量',
            align:"center",
            dataIndex: 'reqQty',
            width: 110
          },
          {
            title: '采购数量',
            align:"center",
            dataIndex: 'purQty',
            width: 110
          },
          {
            title: '未采数量',
            align:"center",
            dataIndex: 'unpurQty',
            width: 110
          },
          {
            title: '状态',
            align:"center",
            dataIndex: 'status_dictText',
            scopedSlots: { customRender: 'status_dictText' },
            width: 70
          },
          {
            title: '采购员',
            align:"center",
            dataIndex: 'buyer_dictText',
            width: 100
          },
          {
            title:'需求日期',
            align:"center",
            dataIndex: 'reqDate',
            width: 100,
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title: '用途',
            align:"center",
            dataIndex: 'uses',
            scopedSlots: { customRender: 'uses' },
            width: 140
          },
          {
            title:'备注',
            align:"center",
            scopedSlots: { customRender: 'remark' },
            dataIndex: 'remark',
            width: 140
          },
        ],
        url: {
          list: "/mm/purchaseRequisition/queryDetailPageListByMainId",
        },
      }
    },
    watch:{
      'initQueryParam.mainId':function(val) {
        if(val){
          this.loadData();
        }
      }
    },
    created() {
    },
    methods: {
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        if(!this.initQueryParam.mainId){
          return;
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        Object.assign(this.queryParam, this.initQueryParam);
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
      getStatusColor(value){
        if(value === '01'){
          // 申请
          return 'blue';
        }else if(value === '02'){
          // 采购
          return 'red';
        }else if(value === '03'){
          // 完成
          return 'green';
        }else {
          // 关闭
          return '#C0C0C0';
        }
      },

    }
  }
</script>
<style scoped>
/*.ant-card-body .table-operator {*/
/*  margin-bottom: 0px;*/
/*}*/
</style>